package com.gzc.just.play.last.war.common.share.config;

import com.gzc.just.play.last.war.common.share.data.DataAccessService;
import com.gzc.just.play.last.war.common.share.data.impl.SQLiteDataAccessService;
import com.gzc.just.play.last.war.common.share.cache.UnifiedCacheService;
import com.gzc.just.play.last.war.common.share.cache.impl.CaffeineCacheService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;

/**
 * 数据访问配置类
 * 根据环境自动选择数据访问服务实现
 */
@Configuration
public class DataAccessConfig {
    
    private static final Logger logger = LoggerFactory.getLogger(DataAccessConfig.class);
    
    /**
     * 开发环境数据访问服务
     */
    @Bean
    @Profile("dev-all-in-one")
    @Primary
    public DataAccessService sqliteDataAccessService() {
        logger.info("Initializing SQLite data access service (development environment)");
        return new SQLiteDataAccessService();
    }
    
    /**
     * 开发环境缓存服务
     */
    @Bean
    @Profile("dev-all-in-one")
    @Primary
    public UnifiedCacheService caffeineCacheService() {
        logger.info("Initializing Caffeine cache service (development environment)");
        return new CaffeineCacheService();
    }
    
    /**
     * 生产环境数据访问服务（需要实现MySQL版本）
     * 这里暂时返回null，需要后续实现MySQLDataAccessService
     */
    @Bean
    @Profile("prod")
    @Primary
    public DataAccessService mysqlDataAccessService() {
        logger.info("Initializing MySQL data access service (production environment)");
        // TODO: Implement MySQLDataAccessService
        // return new MySQLDataAccessService();
        logger.warn("MySQL data access service not yet implemented, using default implementation");
        return null;
    }
    
    /**
     * 生产环境缓存服务（需要实现Redis版本）
     * 这里暂时返回null，需要后续实现RedisCacheService
     */
    @Bean
    @Profile("prod")
    @Primary
    public UnifiedCacheService redisCacheService() {
        logger.info("Initializing Redis cache service (production environment)");
        // TODO: Implement RedisCacheService
        // return new RedisCacheService();
        logger.warn("Redis cache service not yet implemented, using default implementation");
        return null;
    }
}